package com.qfedu.service.impl;

import com.qfedu.mapper.TaskPlanMapper;
import com.qfedu.model.Branch;
import com.qfedu.model.TaskPlan;
import com.qfedu.page.PageResult;
import com.qfedu.page.QueryPageBean;
import com.qfedu.service.ITaskPlanService;
import com.qfedu.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 概述:
 *
 * @Author: Tbh
 * @Date: 2022/7/1 20:21
 */

@Service
public class TaskPlanServiceImpl implements ITaskPlanService {

    @Autowired
    private TaskPlanMapper taskPlanMapper;

    @Override
    public PageResult findPage(QueryPageBean queryPage) {

        Integer currentPage = queryPage.getCurrentPage();
        Integer pageSize = queryPage.getPageSize();

        List<TaskPlan> page = taskPlanMapper.findPage((currentPage - 1) * pageSize,pageSize);

        Long count = taskPlanMapper.count();

        return new PageResult(count,page);
    }

    @Override
    @Transactional
    public int addTaskPlan(TaskPlan taskPlan) {
        taskPlan.setTid(UUIDUtils.uuid());
        taskPlan.setUpdatetime(new Date());
        int row = taskPlanMapper.addTaskPlan(taskPlan);
        return row;
    }

    @Override
    public TaskPlan findByTid(String tid) {
        return taskPlanMapper.findByTid(tid);
    }

    @Override
    @Transactional
    public int edit(TaskPlan taskPlan) {
        taskPlan.setUpdatetime(new Date());
        return taskPlanMapper.updateTaskPlan(taskPlan);
    }

    @Override
    @Transactional
    public int deleteByTid(String tid) {
        return taskPlanMapper.deleteByTid(tid);
    }
}
